home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / ObjectTcl-1.1 / tkAppInit.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-30  |  3.4 KB  |  151 lines

  1. /* 
  2.  * tkAppInit.c --
  3.  *
  4.  *    Provides a default version of the Tcl_AppInit procedure for
  5.  *    use in wish and similar Tk-based applications.
  6.  *
  7.  * Copyright (c) 1993 The Regents of the University of California.
  8.  * Copyright (c) 1994 Sun Microsystems, Inc.
  9.  *
  10.  * See the file "license.terms" for information on usage and redistribution
  11.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12.  */
  13.  
  14. #ifndef lint
  15. static char sccsid[] = "@(#) tkAppInit.c 1.12 94/12/17 16:30:56";
  16. #endif /* not lint */
  17.  
  18. #include <tk.h>
  19. #include "Otcl.H"
  20. #include "OtclOserver.H"
  21.  
  22. /*
  23.  * The following variable is a special hack that is needed in order for
  24.  * Sun shared libraries to be used for Tcl.
  25.  */
  26.  
  27. #ifdef NEED_MATHERR
  28. extern int matherr();
  29. int *tclDummyMathPtr = (int *) matherr;
  30. #endif
  31.  
  32. extern "C" void Tk_Main (int, char **);
  33.  
  34. /*
  35.  *----------------------------------------------------------------------
  36.  *
  37.  * main --
  38.  *
  39.  *    This is the main program for the application.
  40.  *
  41.  * Results:
  42.  *    None: Tk_Main never returns here, so this procedure never
  43.  *    returns either.
  44.  *
  45.  * Side effects:
  46.  *    Whatever the application does.
  47.  *
  48.  *----------------------------------------------------------------------
  49.  */
  50.  
  51. int
  52. main(int argc, char **argv)
  53. {
  54.     Tk_Main(argc, argv);
  55.     return 0;            /* Needed only to prevent compiler warning. */
  56. }
  57.  
  58.  
  59.  
  60.  
  61. #ifdef OTCL_DP
  62. static void readableFd (ClientData cd, int)
  63. {
  64.    int fd = (int)cd;
  65.    OtclOserver::readableFd(fd);
  66. }
  67.  
  68. static void addReadFd (int fd)
  69. {
  70.    Tk_CreateFileHandler(fd,TK_READABLE | TK_EXCEPTION,readableFd,(ClientData)fd);
  71. }
  72.  
  73. static void rmvReadFd (int fd)
  74. {
  75.    Tk_DeleteFileHandler(fd);
  76. }
  77. #endif
  78.  
  79. /*
  80.  *----------------------------------------------------------------------
  81.  *
  82.  * Tcl_AppInit --
  83.  *
  84.  *    This procedure performs application-specific initialization.
  85.  *    Most applications, especially those that incorporate additional
  86.  *    packages, will have their own version of this procedure.
  87.  *
  88.  * Results:
  89.  *    Returns a standard Tcl completion code, and leaves an error
  90.  *    message in interp->result if an error occurs.
  91.  *
  92.  * Side effects:
  93.  *    Depends on the startup script.
  94.  *
  95.  *----------------------------------------------------------------------
  96.  */
  97.  
  98. int
  99. Tcl_AppInit(Tcl_Interp *interp)
  100. {
  101.     Tk_Window main;
  102.  
  103.     main = Tk_MainWindow(interp);
  104.  
  105.     if (Tcl_Init(interp) == TCL_ERROR) {
  106.     return TCL_ERROR;
  107.     }
  108.     if (Tk_Init(interp) == TCL_ERROR) {
  109.     return TCL_ERROR;
  110.     }
  111.  
  112.     if(Otcl_Init(interp) == TCL_ERROR) {
  113.          return TCL_ERROR;
  114.     }
  115.  
  116.     /*
  117.      * Object Tcl - DP needs to register some functions to bind the
  118.      * object server with Tk's event loop.
  119.      */
  120. #ifdef OTCL_DP
  121.      OtclOserver::addReadFd = addReadFd;
  122.      OtclOserver::rmvReadFd = rmvReadFd;
  123. #endif
  124.  
  125.     /*
  126.      * Call the init procedures for included packages.  Each call should
  127.      * look like this:
  128.      *
  129.      * if (Mod_Init(interp) == TCL_ERROR) {
  130.      *     return TCL_ERROR;
  131.      * }
  132.      *
  133.      * where "Mod" is the name of the module.
  134.      */
  135.  
  136.     /*
  137.      * Call Tcl_CreateCommand for application-specific commands, if
  138.      * they weren't already created by the init procedures called above.
  139.      */
  140.  
  141.     /*
  142.      * Specify a user-specific startup file to invoke if the application
  143.      * is run interactively.  Typically the startup file is "~/.apprc"
  144.      * where "app" is the name of the application.  If this line is deleted
  145.      * then no user-specific startup file will be run under any conditions.
  146.      */
  147.  
  148.     tcl_RcFileName = "~/.wishrc";
  149.     return TCL_OK;
  150. }
  151.